<template>
  <div class="informationBox">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item>
        <el-button type="primary" icon="el-icon-circle-plus-outline" @click="add('add')">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableTypeList" border height="605px">
      <el-table-column prop="name" label="类型名称" align="center"> </el-table-column>
      <el-table-column prop="tag" label="类型简称" align="center"> </el-table-column>
      <el-table-column label="操作" width="150">
        <template slot-scope="scope">
          <el-button icon="el-icon-edit" type="text" @click="add('edit',scope.row)">修改</el-button>
          <el-button icon="el-icon-delete" type="text" @click="removeData(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="total, prev, pager, next, sizes,jumper" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" :current-page="pageNum" :page-size="pageSize" :page-sizes="[10,20, 50,100]"
      :total="total">
    </el-pagination>
    <typeAdd :visible.sync="visible" ref="typeAddRef" @addSuccess="getTableData"></typeAdd>
  </div>
</template>

<script>
  import typeAdd from './components/typeAdd.vue'
  import {
    basicStoShelf, //获取货位类型
    deleteBasicStoShelf
  } from "@/api/index/warehouse";
  export default {
    data() {
      return {
        tableTypeList: [],
        total: 0,
        pageNum: 1,
        pageSize: 10,
        formInline: {},
        visible: false
      }
    },
    created() {
      this.getTableData();
    },
    components: {
      typeAdd
    },
    methods: {
      //删除
      removeData(row) {
        this.$confirm(`确认要删除此项任务吗？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteBasicStoShelf(row.id).then(res => {
            this.$message.success(res.msg);
            this.getTableData();
          })
        }).catch(() => {
          // 用户取消了操作，恢复原始状态
          this.$message({
            type: 'info',
            message: '操作已取消'
          });
        });
      },
      //新增修改
      add(type, data) {
        this.visible = true;
        this.$refs.typeAddRef.openDialog(type, data);
      },
      //获取类型
      getTableData() {
        let param = {
          pageNum: this.pageNum,
          pageSize: this.pageSize
        }
        basicStoShelf(param).then(res => {
          this.tableTypeList = res.rows;
          this.total = res.total;
        })
      },
      //切换pagesize
      handleSizeChange(newsize) {
        this.pageNum = 1;
        this.pageSize = newsize;
        this.getTableData();
      },
      //切换pageNum
      handleCurrentChange(newpage) {
        this.pageNum = newpage;
        this.getTableData();
      },
    }
  }
</script>
<style lang="scss" scoped>
  .informationBox {
    padding: 15px 0px 15px 15px;
  }

  .el-pagination {
    float: right;
    margin: 20px;
  }
</style>
